home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #1 / Amiga Plus CD - 2000 - No. 1.iso / Games / Starter / JST / Developer / sources / OSEmu / graphics.s < prev    next >
Encoding:
Text File  |  1999-12-03  |  20.3 KB  |  1,013 lines

  1. * $Id: graphics.s 1.1 1999/02/03 04:10:07 jotd Exp jotd $
  2. **************************************************************************
  3. *    GRAPHICS LIBRARY
  4. **************************************************************************
  5. **************************************************************************
  6. *    INITIALIZATION
  7. **************************************************************************
  8.  
  9. GFXINIT        move.l    _gfxbase,d0
  10.         beq    .init
  11.         rts
  12.  
  13. .init        move.l    #1056,d0    ;-_LVOWriteChunkyPixels,d0
  14.         move.l    #$220,d1
  15.         lea    _gfxname,a0
  16.         bsr    _InitLibrary
  17.         move.l    d0,a0
  18.         move.l    d0,_gfxbase
  19.         
  20.         patch    _LVOOwnBlitter(a0),MYRTS(PC)
  21.         patch    _LVODisownBlitter(a0),MYRTS(PC)
  22.         patch    _LVOInitView(a0),_InitView(PC)
  23.         patch    _LVOInitVPort(a0),_InitVPort(PC)
  24.         patch    _LVOFreeVPortCopLists(a0),_FreeVPortCopLists(PC)
  25.         patch    _LVOInitBitMap(a0),_InitBitMap(PC)
  26.         patch    _LVOInitRastPort(a0),_InitRastPort(PC)
  27.         patch    _LVOMakeVPort(a0),_MakeVPort(PC)
  28.         patch    _LVOMrgCop(a0),_MrgCop(PC)
  29.         patch    _LVOCWait(a0),_CWait(PC)    ; added by JOTD
  30.         patch    _LVOCMove(a0),_CMove(PC)    ; added by JOTD
  31.         patch    _LVOCBump(a0),_CBump(PC)    ; added by JOTD
  32.         patch    _LVOLoadView(a0),_LoadView(PC)
  33.         patch    _LVOLoadRGB4(a0),_LoadRGB4(PC)
  34.         patch    _LVOSetRGB4(a0),_SetRGB4(PC)
  35.         patch    _LVOFreeSprite(a0),_FreeSprite(PC)
  36.         patch    _LVOGetSprite(a0),_GetSprite(PC)
  37.         patch    _LVOChangeSprite(a0),_ChangeSprite(PC)
  38.         patch    _LVOMoveSprite(a0),_MoveSprite(PC)
  39.         patch    _LVOWaitBlit(a0),_WaitBlit(PC)
  40.         patch    _LVOBltBitMap(a0),_BltBitMap(PC)
  41.         patch    _LVOVBeamPos(a0),_VBeamPos(PC)
  42.         patch    _LVODraw(a0),MYRTS(PC)
  43.         patch    _LVOMove(a0),_SETMOVE(PC)
  44.         patch    _LVOSetAPen(a0),_SETAPEN(PC)
  45.         patch    _LVOSetBPen(a0),_SETBPEN(PC)
  46.         patch    _LVOSetDrMd(a0),_SETDRAWMODE(PC)
  47.         patch    _LVOWaitTOF(a0),_WaitTOF(PC)
  48. ;;        patch    _LVOWaitBOVP(a0),_WaitBOVP(PC)        ; -- added by JOTD
  49.         patch    _LVORectFill(a0),_RectFill(PC)        ; -- added by JOTD
  50.         patch    _LVOSetRast(a0),_SetRast(PC)        ; -- added by JOTD
  51.         patch    _LVOInitTmpRas(a0),_InitTmpRas(PC)    ; -- added by JOTD
  52.         patch    _LVOInitArea(a0),_InitArea(PC)        ; -- added by JOTD
  53.         patch    _LVOReadPixel(a0),_ReadPixel(PC)
  54.         patch    _LVOWritePixel(a0),_WritePixel(PC)
  55.         patch    _LVOBltTemplate(a0),_BltTemplate(PC)
  56.         patch    _LVOAllocRaster(A0),_ALLOCRASTER(PC)
  57.         patch    _LVOFreeRaster(A0),_FREERASTER(PC)
  58.         patch    _LVOBltClear(A0),_BLTCLEAR(PC)
  59.         patch    _LVOGetColorMap(A0),_GETCOLORMAP(PC)
  60.         patch    _LVOFreeColorMap(A0),_FREECOLORMAP(PC)
  61.  
  62.         patch    _LVOOpenFont(A0),_OPENFONT(PC)
  63.         patch    _LVOSetFont(A0),_SETFONT(PC)
  64.         patch    _LVOText(A0),_PRINTTEXT(PC)
  65.  
  66.         MOVE.L    #MYVIEW,gb_ActiView(A0)
  67.         lea    STDCOPPER(PC),a1
  68.         MOVE.L    a1,(gb_LOFlist,A0)
  69.         MOVE.L    a1,(gb_SHFlist,A0)
  70.         MOVE.L    a1,(_custom+cop2lc)
  71.         lea    CPJMP2,a1
  72.         move.l    a1,(gb_copinit,a0)
  73.         MOVE.L    a1,(_custom+cop1lc)
  74.  
  75.         moveq    #4,d0                ;pal
  76.         cmp.l    #PAL_MONITOR_ID,_monitor
  77.         beq    .1
  78.         moveq    #1,d0                ;ntsc
  79. .1        MOVE.W    d0,(gb_DisplayFlags,A0)
  80.  
  81.         clr.b    (gb_SpriteReserved,a0)
  82.  
  83.         clr.l    -(a7)                ;TAG_DONE
  84.         pea    RESTORECOPPER2(pc)
  85.         move.l    #WHDLTAG_CBSWITCH_SET,-(a7)
  86.         move.l    a7,a0
  87.         move.l    _RESLOAD(pc),a1
  88.         jsr    (resload_Control,a1)
  89.         lea    (12,a7),a7                      ;restore sp
  90.         
  91.         tst.w    (_custom+copjmp1)
  92.         move.w    #DMAF_SETCLR!DMAF_MASTER!DMAF_COPPER!DMAF_BLITTER,(_custom+dmacon)
  93.  
  94.         rts
  95.  
  96. RESTORECOPPER2    move.l    a1,.save
  97.         move.l    _gfxbase,a1
  98.         move.l    (gb_LOFlist,a1),(_custom+cop2lc)
  99.         move.l    .save,a1
  100.         jmp    (A0)
  101.  
  102.     CNOP 0,4
  103. .save        dc.l    0
  104. CPJMP2        dc.l    $0201fffe    ;wait 0,2
  105.         DC.L    $008A0000
  106. STDCOPPER    DC.L    $FFFFFFFE
  107.  
  108. MYVIEW
  109.     DC.L    _INITVIEWPORT
  110.     DC.L    STDCOPPER
  111.     DC.L    STDCOPPER
  112.     DC.W    0
  113.     DC.W    0
  114.     DC.W    0
  115.  
  116. _INITVIEWPORT
  117.     DC.L    $EEEEEEEE
  118.     DC.L    $EEEEEEEE
  119.     DC.L    $EEEEEEEE
  120.     DC.L    $EEEEEEEE
  121.     DC.L    $EEEEEEEE
  122.     DC.L    0
  123.     DC.W    0
  124.     DC.W    0
  125.     DC.W    0
  126.     DC.W    0
  127.     DC.W    0
  128.     DC.B    0,0
  129.     DC.L    _INITRASINFO
  130.  
  131. _INITRASINFO
  132.     DC.L    0
  133.     DC.L    $EEEEEEEE
  134.     DC.W    0
  135.     DC.W    0
  136.  
  137. _FONTTABLE
  138.     DC.L    _TOPAZNAME,_TOPAZ8FONT
  139.     DC.L    0
  140.  
  141. _TOPAZNAME
  142.     DC.B    'topaz.font',0
  143.     EVEN
  144.  
  145. _TOPAZ8FONT
  146.     DC.L    0,0,0,0,0        ;EMPTY MESSAGEPORT
  147.     DC.W    8            ;YSIZE
  148.     DC.B    0            ;NO SPECIAL STYLE
  149.     DC.B    $41            ;FONTFLAGS:DESIGNED,ROMFONT
  150.     DC.W    8            ;XSIZE
  151.     DC.W    6            ;BASELINE
  152.     DC.W    1            ;FETT: 1 PIXEL VERSETZT
  153.     DC.W    1            ;1 TASK BENUTZT FONT (DUMMY)
  154.     DC.B    $20            ;LOWEST CHAR IS SPACE
  155.     DC.B    $FF            ;HIGHEST CHAR IS "y
  156.     DC.L    _TOPAZ8DATA        ;FONTIMAGES
  157.     DC.W    $C0            ;MODULO
  158.     DC.L    _TOPAZ8OFFSETS        ;OFFSETTABLES
  159.     DC.L    0            ;NON PROPORTIONAL FONT
  160.     DC.L    0            ;NO KERNING
  161.  
  162. _TOPAZ8DATA
  163.     INCBIN    REPLFONT_DATA
  164.  
  165. _TOPAZ8OFFSETS
  166.     INCBIN    REPLFONT_BITS
  167.  
  168. **************************************************************************
  169. *    GRAPHICS LIBRARY FUNCTIONS
  170. **************************************************************************
  171.  
  172. _FreeVPortCopLists:
  173.     move.l    A2,-(A7)
  174.     move.l    A0,A2
  175.     move.l    #200,D1
  176.     move.l    (vp_DspIns,a2),A1
  177.     move.l    (4),A6
  178.     jsr    (_LVOFreeMem,A6)
  179.  
  180.     clr.l    (vp_DspIns,a2)
  181.  
  182.     ; nothing allocated for the 3 of them below
  183.  
  184.     clr.l    (vp_SprIns,a2)
  185.     clr.l    (vp_ClrIns,a2)
  186.     clr.l    (vp_UCopIns,a2)
  187.  
  188.     move.l    (a7)+,A2
  189.     rts
  190.  
  191. _InitTmpRas:
  192.     move.l    A1,(A0)
  193.     move.l    D0,4(A0)
  194.     move.l    A0,D0
  195.     rts
  196.  
  197. _InitArea:
  198.     MOVE.L    A1,4(A0)
  199.     MOVE.L    A1,(A0)
  200.     MOVE    D0,18(A0)
  201.     ASL.L    #2,D0
  202.     ADDA    D0,A1
  203.     MOVE.L    A1,12(A0)
  204.     MOVE.L    A1,8(A0)
  205.     CLR    16(A0)
  206.     RTS
  207.     
  208. _InitView
  209.     movem.l    D0/A0,-(A7)
  210.     move.w    #$8,D0
  211. .zero
  212.     clr.w    (A0)+
  213.     dbf    D0,.zero
  214.     movem.l    (A7)+,D0/A0
  215.     rts
  216.  
  217. _InitVPort    
  218.     movem.l    D0/A0,-(A7)
  219.     move.w    #9,D0
  220. .zero
  221.     clr.l    (A0)+
  222.     dbf    D0,.zero
  223.     movem.l    (A7)+,D0/A0    
  224.     rts
  225.  
  226. _InitRastPort
  227.     MOVE.L    #$EEEEEEEE,(A1)
  228.     MOVE.L    #0,rp_BitMap(A1)
  229.     MOVE.L    #$EEEEEEEE,rp_AreaPtrn(A1)
  230.     MOVE.L    #$EEEEEEEE,rp_TmpRas(A1)
  231.     MOVE.L    #$EEEEEEEE,rp_AreaInfo(A1)
  232.     MOVE.L    #0,rp_GelsInfo(A1)
  233.     MOVE.L    #$FF0000FF,rp_Mask(A1)    
  234.     MOVE.L    #$01000000,rp_DrawMode(A1)
  235.     CLR.L    rp_Flags(A1)
  236.     CLR.L    rp_cp_x(A1)
  237.     CLR.L    rp_minterms(A1)
  238.     CLR.L    rp_minterms+4(A1)
  239.     CLR.L    rp_PenWidth(A1)
  240.     MOVE.L    #_TOPAZ8FONT,rp_Font(A1)
  241.     CLR.W    rp_AlgoStyle(A1)
  242.     MOVE.L    #$00080008,rp_TxHeight(A1)
  243.     MOVE.L    #$00060008,rp_TxBaseline(A1)
  244.     CLR.L    rp_RP_User(A1)
  245.     RTS
  246.  
  247. _SETAPEN
  248.     MOVE.B    D0,rp_FgPen(A1)
  249.     RTS
  250.  
  251. _SETBPEN
  252.     MOVE.B    D0,rp_BgPen(A1)
  253.     RTS
  254.  
  255. _SETDRAWMODE
  256.     MOVE.B    D0,rp_DrawMode(A1)
  257.     RTS
  258.  
  259. _SETMOVE
  260.     MOVE.W    D0,rp_cp_x(A1)
  261.     MOVE.W    D1,rp_cp_y(A1)
  262.     RTS
  263.  
  264. _BLTCLEAR    AND.W    #2,D1
  265.     BNE.S    .FAIL
  266.     LSR.W    #1,D0
  267.     SUBQ.W    #1,D0
  268. .1    CLR.W    (A1)+
  269.     DBF    D0,.1
  270.     RTS
  271.  
  272. .FAIL        pea    _LVOBltClear
  273.         pea    _gfxname
  274.         bra    _emufail
  275.  
  276. _ALLOCRASTER
  277.     ADD.W    #$F,D0
  278.     LSR.W    #3,D0
  279.     AND.W    #$FFFE,D0
  280.     MULU    D1,D0
  281.     MOVEQ.L    #MEMF_CHIP!MEMF_PUBLIC,D1
  282.     BSR.W    ALLOCM
  283.     RTS
  284.  
  285. _FREERASTER
  286.     ADD.W    #$F,D0
  287.     LSR.W    #3,D0
  288.     AND.W    #$FFFE,D0
  289.     MULU    D1,D0
  290.     MOVE.L    A0,A1
  291.     BSR.W    FREEM
  292.     RTS
  293.  
  294. _GETCOLORMAP
  295.     MOVE.L    D0,-(A7)
  296.     ADD.L    D0,D0
  297.     ADDQ.L    #8,D0
  298.     MOVE.L    #MEMF_CLEAR,D1
  299.     BSR.W    ALLOCM
  300.     TST.L    D0
  301.     BEQ.S    .FAIL
  302.     MOVE.L    D0,A0
  303.     MOVE.L    (A7)+,D1
  304.     MOVE.W    D1,cm_Count(A0)
  305.     LEA.L    8(A0),A1
  306.     MOVE.L    A1,cm_ColorTable(A0)
  307.     CMP.W    #$20,D1
  308.     BLS.S    .1
  309.     MOVEQ.L    #$20,D1
  310. .1    LEA.L    .COLORTAB(PC),A0
  311. .2    MOVE.W    (A0)+,(A1)+
  312.     SUBQ.W    #1,D1
  313.     BNE.S    .2
  314.  
  315. .FAIL    RTS
  316.  
  317. .COLORTAB
  318.     DC.B    $00,$00,$0F,$00,$00,$F0,$0F,$F0
  319.     DC.B    $00,$0F,$0F,$0F,$00,$FF,$0F,$FF
  320.     DC.B    $06,$20,$0E,$50,$09,$F1,$0E,$B0
  321.     DC.B    $05,$5F,$09,$2F,$00,$F8,$0C,$CC
  322.     DC.B    $00,$00,$01,$11,$02,$22,$03,$33
  323.     DC.B    $04,$44,$05,$55,$06,$66,$07,$77
  324.     DC.B    $08,$88,$09,$99,$0A,$AA,$0B,$BB
  325.     DC.B    $0C,$CC,$0D,$DD,$0E,$EE,$0F,$FF
  326.  
  327. _FREECOLORMAP    ;A0-*COLORMAP
  328.     MOVE.L    (A2),-(A7)
  329.     MOVE.L    A0,A2
  330.     MOVE.L    cm_ColorTable(A2),A1
  331.     MOVEQ.L    #0,D0
  332.     MOVE.W    cm_Count(A2),D0
  333.     ADD.L    D0,D0
  334.     ADDQ.L    #7,D0
  335.     AND.L    #$FFFFFFF8,D0
  336.     BSR.W    FREEM
  337.  
  338.     MOVE.L    A2,A1
  339.     MOVEQ.L    #8,D0
  340.     BSR.W    FREEM
  341.     MOVE.L    (A7)+,A2
  342.     RTS
  343.  
  344. _OPENFONT    
  345.         move.l    a2,-(a7)
  346. ;        CMP.W    #8,4(A0)
  347. ;        BNE.S    .ERR
  348.         MOVE.L    (A0),A1
  349.  
  350.         lea    _FONTTABLE(PC),a2
  351. .next        move.l    (a2)+,a0
  352.         move.l    a0,d0
  353.         beq    .ERR
  354.         bsr    _strcmp
  355.         beq    .found
  356.         addq.l    #4,a2
  357.         bra    .next
  358.  
  359. .found        MOVE.L    (A2),D0
  360.         move.l    (a7)+,a2
  361.         rts
  362.  
  363. .ERR        pea    _LVOOpenFont
  364.         pea    _gfxname
  365.         bra    _emufail
  366.  
  367. _SETFONT    MOVE.L    A0,rp_Font(A1)
  368.         CLR.W    rp_AlgoStyle(A1)
  369.         MOVE.W    tf_YSize(A0),rp_TxHeight(A1)
  370.         MOVE.W    tf_XSize(A0),rp_TxWidth(A1)
  371.         MOVE.W    tf_Baseline(A0),rp_TxBaseline(A1)
  372.         MOVE.W    tf_XSize(A0),rp_TxSpacing(A1)
  373.         RTS
  374.  
  375.  
  376. _PRINTTEXT    ;A0-*STRING, A1-*RASTPORT, D0-CHARCOUNT
  377.         MOVEM.L    D2-D7/A2-A6,-(A7)
  378.         MOVE.L    A0,A2            ;keep stringpointer
  379.         MOVE.L    D0,D2
  380.         MOVE.L    rp_Font(A1),A3        ;get font
  381.         MOVE.L    tf_CharLoc(A3),A4    ;get chardescriptionpointer
  382. .NXPRINT    MOVE.L    D2,-(A7)
  383.         MOVE.L    tf_CharData(A3),A5    ;get chardatapointer
  384.         MOVEQ.L    #0,D3
  385.         MOVE.B    (A2)+,D3        ;get char
  386.         CMP.B    tf_HiChar(A3),D3
  387.         BHI.S    .SPACEPRINT
  388.         CMP.B    tf_LoChar(A3),D3
  389.         BHS.S    .OKPRINT
  390. .SPACEPRINT    MOVE.B    tf_LoChar(A3),D3
  391. .OKPRINT    SUB.B    tf_LoChar(A3),D3
  392.         LSL.W    #2,D3
  393.         MOVE.W    (A4,D3.W),D4    ;get charposition on font - bitoffset
  394.         MOVE.W    2(A4,D3.W),D2        ;bitwidth of char
  395.         MOVE.W    D4,D3
  396.         AND.W    #$F,D4            ;bitshift
  397.         AND.W    #$FFF0,D3
  398.         LSR.W    #3,D3            ;byteoffset of char
  399.         MOVE.W    rp_cp_x(A1),D6        ;x-printposition
  400.         MOVE.W    D6,D5
  401.         AND.W    #$F,D6            ;x-bitshift
  402.         AND.W    #$FFF0,D5
  403.         LSR.W    #3,D5
  404.         EXT.L    D5
  405.         MOVE.W    rp_cp_y(A1),D7        ;y-printposition
  406.         SUB.W    tf_Baseline(A3),D7
  407.         MOVE.L    rp_BitMap(A1),A0
  408.         MULU    (A0),D7        ;memoryoffset of the line by * bytesperrow
  409.         ADD.L    D5,D7        ;memoffset of printposition w/o shift
  410.  
  411.         MOVEQ.L    #0,D1            ;print char
  412. .NXLINE        MOVE.L    (A5,D3.W),D5        ;get charline from charsetdata
  413.         LSL.L    D4,D5
  414.         MOVEQ.L    #-1,D0            ;mask rest out
  415.         LSR.L    D2,D0
  416.         NOT.L    D0
  417.         AND.L    D0,D5        ;chardata in D5, beginning with bit 31
  418.         LSR.L    D6,D5
  419.         LSR.L    D6,D0        ;contain now a 'window' of set bits at printpos
  420.         MOVEM.L    D1/D3/D4/D6,-(A7)
  421.         BTST    #0,rp_AlgoStyle(A1)
  422.         BEQ.S    .NOUNDERLINE
  423.         MOVE.W    tf_YSize(A3),D3
  424.         SUBQ.W    #1,D3
  425.         CMP.W    D3,D1
  426.         BNE.S    .NOUNDERLINE
  427.         MOVE.L    D0,D5
  428. .NOUNDERLINE    MOVE.L    D0,D3
  429.         NOT.L    D3
  430.         MOVEQ.L    #0,D6
  431. .NXPLANE    MOVE.L    D6,D1
  432.         LSL.L    #2,D1
  433.         MOVE.L    bm_Planes(A0,D1.W),A6    ;planepointertable in a6
  434.         MOVE.L    (A6,D7.L),D1        ;screendata
  435.         BTST    #0,rp_DrawMode(A1)    ;test if JAM2
  436.         BNE.S    .JAM2
  437.         OR.L    D5,D1
  438.         BTST    D6,rp_FgPen(A1)
  439.         BNE.S    .MOVETOPLANE
  440.         EOR.L    D5,D1
  441.         BRA.S    .MOVETOPLANE
  442.                         ;now check colors
  443. .JAM2        BTST    D6,rp_BgPen(A1)
  444.         BNE.S    .BGSET
  445.         AND.L    D3,D1            ;clear bits
  446.         BTST    D6,rp_FgPen(A1)
  447.         BEQ.S    .KEEPFG1
  448.         OR.L    D5,D1            ;set bits
  449. .KEEPFG1    BRA.S    .MOVETOPLANE
  450.  
  451. .BGSET        OR.L    D0,D1
  452.         BTST    D6,rp_FgPen(A1)
  453.         BNE.S    .KEEPFG2
  454.         EOR.L    D5,D1
  455. .KEEPFG2
  456. .MOVETOPLANE    MOVE.L    D1,(A6,D7.L)
  457.         ADDQ.L    #1,D6
  458.         CMP.B    bm_Depth(A0),D6        ;for each bitplane
  459.         BLO.S    .NXPLANE
  460.         MOVEM.L    (A7)+,D1/D3/D4/D6
  461.  
  462.         ADD.W    tf_Modulo(A3),A5
  463.         MOVE.L    D7,A6
  464.         ADD.W    bm_BytesPerRow(A0),A6
  465.         MOVE.L    A6,D7
  466.         ADDQ.L    #1,D1
  467.         CMP.W    tf_YSize(A3),D1        ;all lines
  468.         BLO.W    .NXLINE
  469.         ADD.W    D2,rp_cp_x(A1)        ;rp_position moved
  470.         MOVE.L    (A7)+,D2
  471.         SUBQ.L    #1,D2            ;until string is exhausted
  472.         BNE.W    .NXPRINT
  473.         MOVEM.L    (A7)+,D2-D7/A2-A6
  474.         RTS
  475.  
  476. _InitBitMap    ;a0=bm d0=depth d1=width d2=height
  477.         addq.w    #7,d1
  478.         lsr.w    #3,d1
  479.         AND.W    #$FFFE,D1            ;LORDS OF WAR
  480.         move.w    d1,(bm_BytesPerRow,a0)
  481.         move.w    d2,(bm_Rows,a0)
  482.         clr.b    (bm_Flags,a0)
  483.         move.b    d0,(bm_Depth,a0)
  484.         clr.w    (bm_Pad,a0)
  485.         move.l    #$bbbbbbbb,d1
  486. ;        clr.l    d1
  487.         move.l    d1,(bm_Planes,a0)
  488.         move.l    d1,(bm_Planes+4,a0)
  489.         move.l    d1,(bm_Planes+8,a0)
  490.         move.l    d1,(bm_Planes+12,a0)
  491.         move.l    d1,(bm_Planes+16,a0)
  492.         move.l    d1,(bm_Planes+20,a0)
  493.         move.l    d1,(bm_Planes+24,a0)
  494.         move.l    d1,(bm_Planes+28,a0)
  495.         rts
  496.  
  497. _MakeVPort    ;a0=view a1=viewport
  498.         move.l    a2,-(a7)
  499.         movem.l    a0-a1/a6,-(a7)
  500.         move.l    #200,d0
  501.         move.l    #MEMF_CHIP,d1
  502.         move.l    (4),a6
  503.         jsr    (_LVOAllocMem,a6)
  504.         movem.l    (a7)+,a0-a1/a6
  505.         tst.l    d0
  506.         trapeq
  507.         BEQ.W    .ERR
  508.         move.l    d0,a2                ;A2 = coplist
  509.         move.l    a2,(vp_DspIns,a1)
  510.         move.l    (vp_RasInfo,a1),a0
  511.         move.l    (ri_BitMap,a0),a0
  512.         move.w    #diwstrt,(a2)+
  513.         move.w    #$2981,d0
  514.         move.w    d0,(a2)+
  515.         move.w    #diwstop,(a2)+
  516.         move.w    (bm_BytesPerRow,a0),d1
  517.         lsl.w    #3,d1                ;bytes -> pixel
  518.         add.b    d1,d0
  519.         move.w    (bm_Rows,a0),d1
  520.         lsl.w    #8,d1
  521.         add.w    d1,d0
  522.         move.w    d0,(a2)+
  523.         move.l    #ddfstrt<<16+$0038,(a2)+
  524.         move.l    #ddfstop<<16+$00d0,(a2)+
  525.         move.l    #bplcon1<<16,(a2)+
  526.         move.l    #bpl1mod<<16,(a2)+
  527.         move.l    #bpl2mod<<16,(a2)+
  528.         move.w    #bplcon0,(a2)+
  529.         moveq    #0,d0
  530.         move.b    (bm_Depth,a0),d0
  531.         ror.w    #4,d0
  532.         or.w    #$200,d0
  533.         move.w    d0,(a2)+
  534.         move.b    (bm_Depth,a0),d0
  535.         lea    (bm_Planes,a0),a0
  536.         move.w    #bplpt,d1
  537. .lp        move.w    d1,(a2)+
  538.         addq.w    #2,d1
  539.         move.w    (a0)+,(a2)+
  540.         move.w    d1,(a2)+
  541.         addq.w    #2,d1
  542.         move.w    (a0)+,(a2)+
  543.         subq.b    #1,d0
  544.         bne    .lp
  545.         move.l    #dmacon<<16+DMAF_SETCLR+DMAF_RASTER,(a2)+
  546.         moveq    #-2,d0
  547.         move.l    d0,(a2)+
  548.         move.l    (a7)+,a2
  549.         rts
  550.  
  551. .ERR        pea    _LVOMakeVPort
  552.         pea    _gfxname
  553.         bra    _emufail
  554.  
  555. _CMove:
  556.     move.w    D0,copper_instruction
  557.     move.w    D1,copper_instruction+2
  558.     rts
  559.  
  560. _CWait:
  561.     move.b    D0,copper_instruction
  562.     move.b    D1,copper_instruction+1
  563.     move.w    #$FFFE,copper_instruction+2
  564.     rts
  565.  
  566. _CBump:
  567.     move.l    A0,-(A7)
  568.     move.l    copper_pointer,A0
  569.     move.l    copper_instruction(pc),(A0)+
  570.     move.l    A0,copper_pointer
  571.     move.l    #$FFFFFFFE,(A0)
  572.     move.l    (A7)+,A0
  573.     rts
  574.  
  575. copper_instruction:
  576.     dc.l    0
  577. copper_pointer:
  578.     dc.l    copper_buffer
  579. copper_buffer:
  580.     dc.l    $FFFFFFFE
  581.     blk.l    $1000,0
  582.  
  583. _MrgCop        ;a1=view
  584.         move.l    (v_ViewPort,a1),a0
  585.         cmp.l    #$FFFFFFFE,copper_buffer
  586.         bne    .nouser
  587.         move.l    #copper_buffer,(v_LOFCprList,a1)
  588.         rts
  589.  
  590. .nouser
  591.         move.l    (vp_DspIns,a0),(v_LOFCprList,a1)
  592.         rts
  593.  
  594. _MrgCop_old        ;a1=view
  595.         move.l    (v_ViewPort,a1),a0
  596.         move.l    (vp_DspIns,a0),(v_LOFCprList,a1)
  597.         rts
  598.  
  599. _LoadView    ;a1=view
  600.         move.l    a1,d0
  601.         beq    .noview
  602.         move.l    (v_LOFCprList,a1),d0
  603.         beq    .fail
  604.         move.l    d0,(gb_LOFlist,a6)
  605.         move.l    d0,(_custom+cop2lc)
  606.         rts
  607.  
  608. .noview        CLR.L    (gb_ActiView,a6)
  609.         MOVE.L    #STDCOPPER,(gb_LOFlist,a6)
  610.         move.l    (v_SHFCprList,a1),(gb_SHFlist,a6)
  611.         rts
  612.         
  613. .fail        GFXFAIL    _LVOLoadView
  614.  
  615. _LoadRGB4    ;a0=viewport a1=colors d0=count
  616.         bsr    _waitvb
  617.         lea    (_custom+color),a0
  618. .cpy        move.w    (a1)+,(a0)+
  619.         subq.w    #1,d0
  620.         bne    .cpy
  621.         rts
  622.  
  623. _SetRGB4    ;a0=viewport d0=pen d1=red d2=green d3=blue
  624.     ;    bsr    _waitvb
  625.         lea    (_custom+color),a0
  626.         ext.w    d0
  627.         add.w    d0,a0
  628.         add.w    d0,a0
  629.         lsl.w    #4,d1
  630.         or.w    d2,d1
  631.         lsl.w    #4,d1
  632.         or.w    d3,d1
  633.         move.w    d1,(a0)
  634.         rts
  635.  
  636. _VBeamPos    move.l    (_custom+vposr),d0
  637.         lsr.l    #8,d0
  638.         and.l    #$1ff,d0
  639.         rts
  640.  
  641. _WaitTOF    BSR.w    _waitvb
  642.         rts
  643.  
  644. _WaitBOVP:
  645.         bsr.w    _waitvb        ; -- added by JOTD
  646.         rts            ; -- I know this is not the accurate function
  647.  
  648. _ReadPixel    ;d0=x d1=y a1=rastport
  649.         move.l    (rp_BitMap,a1),a0
  650.         ext.l    d0
  651.         ror.l    #3,d0
  652.         cmp.w    (bm_BytesPerRow,a0),d0
  653.         bhs    .bad
  654.         cmp.w    (bm_Rows,a0),d1
  655.         bhs    .bad
  656.         mulu    (bm_BytesPerRow,a0),d1
  657.         add.w    d0,d1            ;byte offset
  658.         rol.l    #3,d0            ;bit offset
  659.         
  660.         movem.l    d2-d4,-(a7)
  661.         moveq    #0,d2
  662.         moveq    #0,d3
  663.         move.b    (bm_Depth,a0),d4
  664.         lea    (bm_Planes,a0),a0
  665.         
  666. .next        move.l    (a0)+,a1
  667.         btst    d0,(a1,d1.l)
  668.         beq    .1
  669.         bset    d2,d3
  670. .1        addq.l    #1,d2
  671.         cmp.b    d2,d4
  672.         bhi    .next
  673.         
  674.         move.l    d3,d0
  675.         movem.l    (a7)+,d2-d4
  676.         rts
  677.  
  678. .bad        moveq    #-1,d0
  679.         rts
  680.  
  681. _WritePixel    ;d0=x d1=y a1=rastport
  682.         move.l    (rp_BitMap,a1),a0
  683.         ext.l    d0
  684.         ror.l    #3,d0
  685.         cmp.w    (bm_BytesPerRow,a0),d0
  686.         bhs    .bad
  687.         cmp.w    (bm_Rows,a0),d1
  688.         bhs    .bad
  689.         mulu    (bm_BytesPerRow,a0),d1
  690.         add.w    d0,d1            ;byte offset
  691.         rol.l    #3,d0            ;bit offset
  692.         
  693.         movem.l    d2-d4,-(a7)
  694.         moveq    #0,d2
  695.         move.b    (rp_FgPen,a1),d3
  696.         move.b    (bm_Depth,a0),d4
  697.         lea    (bm_Planes,a0),a0
  698.         
  699. .next        move.l    (a0)+,a1
  700.         btst    d2,d3
  701.         beq    .clear
  702. .set        bset    d0,(a1,d1.w)
  703.         bra    .1
  704. .clear        bclr    d0,(a1,d1.w)
  705. .1        addq.l    #1,d2
  706.         cmp.b    d2,d4
  707.         bhi    .next
  708.         
  709.         move.l    d3,d0
  710.         movem.l    (a7)+,d2-d4
  711.         rts
  712.  
  713. .bad        moveq    #-1,d0
  714.         rts
  715.  
  716. ; added by JOTD. Untested
  717.  
  718. _SetRast:
  719.     movem.l    D2-D7/A2-A6,-(A7)
  720. ;;    move.l    rp_BitMap(A1),A0    ; pointer on bitmap
  721. ;;    move.w    (bm_BytesPerRow)
  722.     bsr    _SETAPEN
  723.     moveq.l    #0,D0    ; xmin
  724.     moveq.l    #0,D1    ; ymin
  725.     move.l    #320,D2    ; xmax
  726.     move.l    #200,D3 ; ymax
  727.     bsr    _RectFill
  728.     movem.l    (A7)+,D2-D7/A2-A6
  729.     rts
  730.  
  731. ; added by JOTD. Not optimized and not tested AT ALL
  732.  
  733.     ;d0=xmin d1=ymin d2=xmax d3=ymax a1=rastport
  734. _RectFill:
  735.     movem.l    a2/d2-d7,-(A7)
  736.  
  737.     move.l    d0,d7
  738. .loopx
  739. .loopy
  740.     move.l    d0,d5
  741.     move.l    d1,d6
  742.     move.l    a1,a2
  743.     bsr    _WritePixel
  744.     move.l    a2,a1
  745.     move.l    d5,d0
  746.     move.l    d6,d1
  747.     addq.l    #1,d0
  748.     cmp.l    d0,d2
  749.     bcc.b    .loopx    
  750.     move.l    d7,d0
  751.     addq.l    #1,d1
  752.     cmp.l    d1,d3
  753.     bcc.b    .loopy
  754.  
  755.     movem.l    (A7)+,a2/d2-d7
  756.     rts
  757.  
  758.  
  759. **************************************************************************
  760. *    SPRITES
  761. **************************************************************************
  762.  
  763. _FreeSprite    ;d0=pick
  764.         bclr    d0,(gb_SpriteReserved,a6)
  765.         rts
  766.  
  767. _GetSprite    ;a0=sprite d0=pick
  768.         tst.w    d0
  769.         bmi    .any
  770.         bset    d0,(gb_SpriteReserved,a6)
  771.         bne    .error
  772. .end        move.b    d0,(ss_num,a0)
  773.         ext.l    d0
  774.         rts
  775.  
  776. .error        moveq    #-1,d0
  777.         rts
  778.  
  779. .any        cmp.b    (gb_SpriteReserved,a6),d0
  780.         beq    .error
  781. .next        addq.w    #1,d0
  782.         bset    d0,(gb_SpriteReserved,a6)
  783.         bne    .next
  784.         bra    .end
  785.  
  786. _ChangeSprite    ;a0=viewport a1=simplesprite a2=data
  787.         moveq    #0,d0
  788.         move.b    (ss_num,a1),d0
  789.         lsl.w    #2,d0
  790.         lea    (_sprites),a0
  791.         move.l    a2,(a0,d0.w)
  792.         move.w    #DMAF_SETCLR!DMAF_SPRITE,(_custom+dmacon)
  793.         rts
  794.  
  795. _MoveSprite    ;a0=viewport a1=simplesprite d0=x d1=y
  796.         ;129,41 top,left
  797.         move.l    d2,-(a7)
  798.         moveq    #0,d2
  799.         move.b    (ss_num,a1),d2
  800.         lsl.w    #2,d2
  801.         lea    (_sprites),a0
  802.         move.l    (a0,d2.w),a0
  803.         add.w    #129,d0            ;d0 hor
  804.         add.w    #41,d1            ;d1 top
  805.         move.w    d1,d2
  806.         add.w    (ss_height,a1),d2    ;d2 bottom
  807.         move.b    d1,(a0)+        ;top7..top0
  808.         ror.w    #1,d0
  809.         move.b    d0,(a0)+        ;hor8..hor1
  810.         move.b    d2,(a0)+        ;bot7..bot0
  811.         lsr.w    #8,d1
  812.         lsl.w    #7,d2
  813.         addx.w    d2,d2
  814.         addx.w    d1,d1
  815.         addx.w    d0,d0
  816.         addx.w    d1,d1
  817.         move.b    d1,(a0)+
  818.         move.l    (a7)+,d2
  819.         rts
  820.  
  821. **************************************************************************
  822. *    BLITTER
  823. **************************************************************************
  824.  
  825. _WaitBlit
  826. .wait        tst.b    (_ciaa)
  827.         tst.b    (_ciaa)
  828.         btst    #DMAB_BLTDONE-8,(_custom+dmaconr)
  829.         bne.b    .wait
  830.         tst.b    (_ciaa)
  831.         rts
  832.  
  833. _BltBitMap    ;a0=sbitmap d0=sx d1=sy
  834.         ;a1=dbitmap d2=dx d3=dy
  835.         ;d4=width d5=height d6=minterm d7=mask a2=buffer
  836.  
  837.         movem.l    d2-d7/a2-a3,-(a7)
  838.         lea    (_custom),a3
  839.  
  840.         mulu    (bm_BytesPerRow,a0),d1
  841.         ext.l    d0
  842.         ror.l    #4,d0
  843.         add.w    d0,d1
  844.         add.w    d0,d1            ;d1 = byte offset src
  845.  
  846.         mulu    (bm_BytesPerRow,a1),d3
  847.         ext.l    d2
  848.         ror.l    #4,d2
  849.         add.w    d2,d3
  850.         add.w    d2,d3            ;d3 = byte offset dest
  851.  
  852.         lsl.w    #6,d5            ;height
  853.         
  854.         and.w    #$00f0,d6
  855.         or.w    #$070a,d6
  856.         bsr    _WaitBlit
  857.         move.w    d6,(bltcon0,a3)
  858.         
  859.         moveq    #-1,d6
  860.         move.w    d6,(bltadat,a3)
  861.         clr.w    d2
  862.         rol.l    #4,d2            ;d2 = amount of pixels to skip in the first word in dest
  863.         lsr.w    d2,d6            ;d6.w = afwm
  864.         swap    d6
  865.         addq.w    #1,d5            ;d5 = width++ (the first word)
  866.         sub.w    #16,d4
  867.         add.w    d2,d4            ;d4 = pixels left to copy
  868.         ext.l    d4
  869.         ror.l    #4,d4
  870.         add.w    d4,d5            ;d5.w = size
  871.         clr.w    d4
  872.         rol.l    #4,d4            ;d4 = pixels left to copy (0..15)
  873.         beq    .1
  874.         addq.w    #1,d5            ;d5 = width++ (the last word)
  875.         lsr.w    d4,d6            ;d6.w = ~(alwm)
  876.         not.w    d6
  877. .1        move.l    d6,(bltafwm,a3)
  878.         
  879.         clr.w    d0
  880.         rol.l    #4,d0            ;pixel offset src
  881.         sub.w    d0,d2
  882.     ;    spl    d4            ;d4 = 0 if first src word must be preloaded (dma-b)
  883.         bpl    .2
  884.     ;this works only if the destination is word aligned !!!!!!
  885.     ;(in deuteros it is...) normally a second blit is neccessary in this case
  886.         addq.w    #1,d5            ;bltsize++
  887.         subq.w    #2,d3            ;dst-2
  888.         move.w    #0,(bltafwm,a3)
  889.         add.w    #16,d2
  890. .2        ror.w    #4,d2
  891.         move.w    d2,(bltcon1,a3)
  892.         
  893.         move.w    d5,d0
  894.         and.w    #$003f,d0
  895.         add.w    d0,d0
  896.         move.w    (bm_BytesPerRow,a0),d2
  897.         sub.w    d0,d2
  898.         move.w    d2,(bltbmod,a3)
  899.         move.w    (bm_BytesPerRow,a1),d2
  900.         sub.w    d0,d2
  901.         move.w    d2,(bltcmod,a3)
  902.         move.w    d2,(bltdmod,a3)
  903.  
  904.         moveq    #0,d6
  905. .do        btst    d6,d7            ;mask ?
  906.         beq    .next
  907.  
  908.         lsl.w    #2,d6
  909.         move.l    (bm_Planes,a0,d6.w),a2
  910.         add.l    d1,a2
  911.         move.l    (bm_Planes,a1,d6.w),d0
  912.         add.l    d3,d0
  913.         bsr    _WaitBlit
  914.         movem.l    d0/a2,(bltcpt,a3)
  915.         move.l    d0,(bltdpt,a3)
  916.         move.w    d5,(bltsize,a3)
  917.         lsr.w    #2,d6
  918.  
  919. .next        addq.w    #1,d6
  920.         cmp.b    (bm_Depth,a0),d6
  921.         beq    .end
  922.         cmp.b    (bm_Depth,a1),d6
  923.         bne    .do
  924. .end
  925.         movem.l    (a7)+,d2-d7/a2-a3
  926.         rts
  927.  
  928. _BltTemplate    ;a0=src d0=bitoffset d1=modulo
  929.         ;a1=rp d2=x d3=y d4=width d5=height
  930.  
  931.         movem.l    d2-d7/a2-a3,-(a7)
  932.         lea    (_custom),a3
  933.  
  934.         ext.l    d0
  935.         ror.l    #4,d0
  936.         add.w    d0,a0
  937.         add.w    d0,a0            ;a0 = src ptr
  938.  
  939.         move.l    (rp_BitMap,a1),a2
  940.         mulu    (bm_BytesPerRow,a2),d3
  941.         ext.l    d2
  942.         ror.l    #4,d2
  943.         add.w    d2,d3
  944.         add.w    d2,d3            ;d3 = byte offset dest
  945.  
  946.         lsl.w    #6,d5            ;height
  947.         
  948.         bsr    _WaitBlit
  949.         move.w    #$07aa,(bltcon0,a3)
  950.         
  951.         moveq    #-1,d6
  952.         move.w    d6,(bltadat,a3)
  953.         clr.w    d2
  954.         rol.l    #4,d2            ;d2 = amount of pixels to skip in the first word in dest
  955.         lsr.w    d2,d6            ;d6.w = afwm
  956.         swap    d6
  957.         addq.w    #1,d5            ;d5 = width++ (the first word)
  958.         sub.w    #16,d4
  959.         add.w    d2,d4            ;d4 = pixels left to copy
  960.         ext.l    d4
  961.         ror.l    #4,d4
  962.         add.w    d4,d5            ;d5.w = size
  963.         clr.w    d4
  964.         rol.l    #4,d4            ;d4 = pixels left to copy (0..15)
  965.         beq    .1
  966.         addq.w    #1,d5            ;d5 = width++ (the last word)
  967.         lsr.w    d4,d6            ;d6.w = ~(alwm)
  968.         not.w    d6
  969. .1        move.l    d6,(bltafwm,a3)
  970.         
  971.         clr.w    d0
  972.         rol.l    #4,d0            ;pixel offset src
  973.         sub.w    d0,d2
  974.     ;    spl    d4            ;d4 = 0 if first src word must be preloaded (dma-b)
  975.         bpl    .2
  976.     ;this works only if the destination is word aligned !!!!!!
  977.     ;(in deuteros it is...) normally a second blit is neccessary in this case
  978.         addq.w    #1,d5            ;bltsize++
  979.         subq.w    #2,d3            ;dst-2
  980.         move.w    #0,(bltafwm,a3)
  981.         add.w    #16,d2
  982. .2        ror.w    #4,d2
  983.         move.w    d2,(bltcon1,a3)
  984.         
  985.         move.w    d5,d0
  986.         and.w    #$003f,d0
  987.         add.w    d0,d0
  988.         move.w    d1,d2
  989.         sub.w    d0,d2
  990.         move.w    d2,(bltbmod,a3)
  991.         move.w    (bm_BytesPerRow,a2),d2
  992.         sub.w    d0,d2
  993.         move.w    d2,(bltcmod,a3)
  994.         move.w    d2,(bltdmod,a3)
  995.  
  996.         moveq    #0,d6
  997. .do        lsl.w    #2,d6
  998.         move.l    (bm_Planes,a2,d6.w),d0
  999.         add.l    d3,d0
  1000.         bsr    _WaitBlit
  1001.         movem.l    d0/a0,(bltcpt,a3)
  1002.         move.l    d0,(bltdpt,a3)
  1003.         move.w    d5,(bltsize,a3)
  1004.         lsr.w    #2,d6
  1005.  
  1006. .next        addq.w    #1,d6
  1007.         cmp.b    (bm_Depth,a2),d6
  1008.         bne    .do
  1009.  
  1010.         movem.l    (a7)+,d2-d7/a2-a3
  1011.         rts
  1012.  
  1013.